<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/bootstrap/css/bootstrap.min.css">
<link href="__PUBLIC__/Admin/css/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/js/artDialog/skins/blue.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/validform/style.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/ThinkBox/css/ThinkBox.css" media="all">
<script src="__PUBLIC__/Admin/bootstrap/js/jquery.min.js"></script>
<script src="__PUBLIC__/Admin/bootstrap/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/Admin/js/artDialog/artDialog.js"></script>
<script src="__PUBLIC__/Admin/js/artDialog/plugins/iframeTools.js"></script>
<script src="__PUBLIC__/Admin/js/My97DatePicker/WdatePicker.js"></script>
<script src="__PUBLIC__/Js/validform/Validform.js"></script>
<script src="__PUBLIC__/Js/ThinkBox/jquery.ThinkBox.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<script>


//显示图片选择框
function showImgBox(curElement){
	art.dialog.open('{:U('Img/imagesBox')}', {width: 800, height: 500,lock:true,title:'选择图片', ok:function(){
			var d = this.iframe.contentWindow.document;
			var img_url = $(d).find('#Imgselected').attr('img_url');
			$(curElement).parent().find("input[type='hidden']").eq(0).val(img_url);
			$(curElement).val('__PUBLIC__'+img_url);
			$(curElement).focus();
			$(curElement).blur();
			curElement.src = '__PUBLIC__'+img_url;
	}});
}

			 



    function error(msg){
		var d = artDialog({
			title: '操作错误',
			content: msg,
			cancel: false,
			ok: function () {
				
				}
		});
		d.show();
	}
	function success(msg){
		var d = artDialog({
			title: '操作成功',
			content: msg,
			cancel: false,
			ok: function () {
				
				}
		});
		d.show();
	}
	function sall(){
		$('.sall').each(function(index, element) {
            if($(this).attr('checked')=='checked'){
				$(this).attr('checked',false);
			}else{
				$(this).attr('checked',true);
			}
        });
	}
	
	function rall(){
		$('.sall').attr('checked',false);
	}
	//移动内容 到分类
	function movenews(e){
		var ids=new Array();
		$('.sall').each(function(index, element) {
            if($(this).attr('checked')=='checked'){
				ids.push($(this).val());
			}
        });
		if(ids.length>0){
			if(confirm('您确定要移动选中记录吗？')){
			    window.location.href="{:U('move')}?id="+ids.toString()+"&category_id="+e.value;
			}else{
				return false;
			}
		}else{
			error('请选择要移动的记录');
		}
	}
	function delall(){
		var ids=new Array();
		$('.sall').each(function(index, element) {
            if($(this).attr('checked')=='checked'){
				ids.push($(this).val());
			}
        });
		if(ids.length>0){
			if(confirm('您确定要删除选中记录吗？')){
			    window.location.href="{:U('delete')}?id="+ids.toString();
			}else{
				return false;
			}
		}else{
			error('请选择要删除的记录');
		}
	}
	function ajaxText(e){
		var tablename = $(e).parent().attr('tablename');
		var field = $(e).parent().attr('field');
		var id = $(e).parent().attr('id');
		var val = $(e).val();
		$.post('{:U('ajaxText',array('modules_id' => $modules_id))}',{tablename:tablename,field:field,id:id,val:val},function(data){
			if(data.status == 1){
			    $(e).parent().text(data.data);
			}else{
				alert(data.info);
			}
		},'json');
	}
	$(document).ready(function(e) {
		//点击ajax修改文字
		$('span.ajaxText').each(function(index, element) {
			$(this).click(function(e) {
				if($(this).find('input').length == 0){
			    var text = $(this).text();
                var input = $('<input type="text" onBlur="ajaxText(this);" value="">');
				$(this).empty();
				input.appendTo($(this));
				input.keypress(function(e) {
                    if(e.keyCode == 13){
						ajaxText(input);
					}
                });
				input.focus().val(text);
				}
            });
            
        });
		
		//表单验证
		$(".checkoutform:eq(0)").Validform({
			ajaxPost:true,
			tiptype:function(data,s){
				if(s.type == 1){
					$.ThinkBox.success(data,{'delayClose':0});
				}
			},
			callback:function(data){
				if(data.status == 0){
					$.ThinkBox.error(data.info,{'delayClose':200});
					
				}else{
					$.ThinkBox.success(data.info,{'delayClose':200});
					
					    window.location.href = data.url;

				}
			}
	    });
 		//头部菜单
		$('.topmenu').each(function(index, element) {
            $(this).mouseenter(function(e) {
				$(this).addClass('cur');
                $(this).find('ul').removeClass('h');
            });
			$(this).mouseleave(function(e) {
				$(this).removeClass('cur');
                $(this).find('ul').addClass('h');
            });
        });
		
		
        $('.data_list').each(function(index, element) {
            $(this).mouseenter(function(e) {
                $(this).css({'background':'#D7F7F9'});
            });
			$(this).mouseleave(function(e) {
                $(this).css({'background':'#fff'});
            });
			//$(this).find("input[type='checkbox']").click();
			$(this).find("input[type='checkbox']").click(function(){
					if($(this).attr('checked')=='checked'){
					
					    $(this).attr('checked',false);
				    }else{
					    $(this).attr('checked',true);
				    }
				});
			$(this).find("input[type='checkbox']").parent().click(function(e) {
				
                if($(this).find("input[type='checkbox']").attr('checked')=='checked'){
					
					$(this).find("input[type='checkbox']").attr('checked',false);
				}else{
					$(this).find("input[type='checkbox']").attr('checked',true);
				}
            });
        });
		
		//异步更新int字段
		$('.status_btn').each(function(index, element) {
            $(this).click(function(e) {
				$.ajax({
					url:"<?php echo U('ajaxUpdate');?>",
					type:"post",
					data:"data="+$(this).attr('field'),
					dataType:"json",
					success: function(data){
						if(data.status==1){
							$('.status_btn').eq(index).removeClass("status1");
							$('.status_btn').eq(index).removeClass("status0");
							$('.status_btn').eq(index).addClass("status"+data.data);
						}
					}
				});
            });
        });
    });
	
	//更新排序
	//key主键/field更新字段名/el当前按钮对象/url服务端地址
	function update_sort(key,field,el,url){
		var data=new Array();
		$("input[name='"+key+"']").each(function(index, element) {
            data.push($(this).val()+'_'+$(this).parent().parent().find("input[name='"+field+"']").val());
        });
		$.post(url,{
			'sort':data.toString(),
			'field':field, 'tablename': 
		    '{$tablename}'},function(data){
			if(data=='OK'){
				if(el==''){
					success('更新成功');
				}
			}else{
				error('更新失败');
			}
		});
	}
	
	//更新排序,点击移动更新
	function update_sortClick(key,type,el,field,sendurl){
		var data=new Array();
		if(type=='up'){
			$(el).parent().parent().after($(el).parent().parent().prev());
		}else{
			$(el).parent().parent().next().after($(el).parent().parent());
		}
		$("input[name='"+key+"']").each(function(index, element) {
			$(this).parent().parent().find("input[name='"+field+"']").val(index+1);
            data.push($(this).val()+'_'+$(this).parent().parent().find("input[name='"+field+"']").val());
        });
		
		//列新排序
		update_sort(key,field,el,sendurl);
	}
</script>
<body>
<style>

</style>


<div style="margin:10px 0;"><a href="{:U('add',array('modules_id' => $modules_id,'fieldlist' => $fieldlist,'tablename' => $tablename))}" class="btn btn-info btn-xs"><i class="glyphicon glyphicon-plus"></i>添加数据</a></div>

<table class="table table-bordered" width="100%" border="0" cellpadding="0" cellspacing="0">
 <thead>
 <tr><td align="center" class="hidden-xs">ID</td>
 <volist name="fields" id="vo">
    <td align="center" <if condition="$vo['fieldname'] neq 'title' && $vo['fieldname'] neq 'sort'">class="hidden-xs"</if>>{$vo.remark}</td>
    </volist>
    
    <td align="center">操作</td>
  </tr>
</thead>
<volist name="list" id="vo">
  <tr class="data_list">
  <td align="center" class="hidden-xs"><input type="checkbox" name="id" id="id" class="sall" value="{$vo.id}" />{$vo.id}</td>
  
  <volist name="fields" id="svo">
    <td <if condition="$svo['fieldname'] neq 'title' && $svo['fieldname'] neq 'sort'">class="hidden-xs"</if>><eq name="svo['type']" value="0"><div style="max-width:100px;"><span <if condition="$vo[$svo['fieldname']] eq ''">style="padding:0 5px; border:1px dashed #C3C3C3;"</if> class="ajaxText" tablename="{$svo['tablename']}" field="{$svo['fieldname']}" id="{$vo.id}" val="{$vo[$svo['fieldname']]}">{$vo[$svo['fieldname']]}</span></div></eq>
    <eq name="svo['type']" value="4"><if condition="$vo[$svo['fieldname']] neq ''"><img src="{:getThumbPath($vo[$svo['fieldname']])}" width="50" height="50"></if></eq>
    <eq name="svo['type']" value="5"><input name="sort" width="30" type="hidden" value="{$vo[$svo['fieldname']]}" size="4" /><a class="fl" href="javascript:void(0);" onclick="update_sortClick('id','up',this,'sort','{:U('dosort',array('modules_id' => $modules_id,'tablename' => $tablename))}');"><i class="glyphicon glyphicon-arrow-up"></i></a><a class="fr" href="javascript:void(0);" onclick="update_sortClick('id','',this,'sort','{:U('dosort',array('modules_id' => $modules_id,'tablename' => $tablename))}');"><i class="glyphicon glyphicon-arrow-down"></i></a></eq>
    </td>
    </volist>
         
    <td align="center"><a class="btn btn-warning btn-xs" href="{:U('add',array('modules_id' => $modules_id, 'parent_id' => $vo['id'], 'fieldlist' => $fieldlist,'tablename' => $tablename))}">添加子级</a>　<a class="btn btn-success btn-xs" href="{:U('edit',array('modules_id' => $modules_id,'map'=>'id,'.$vo['id'],'fieldlist' => $fieldlist,'tablename' => $tablename))}">编辑</a>　<a class="btn btn-danger btn-xs" href="{:U('delete',array('modules_id' => $modules_id,'id'=>$vo['id'],'tablename' => $tablename))}" onclick="return confirm('您确定要删除这条记录吗？');">删除</a></td>
  </tr>
  
  <volist name="vo['sub']" id="subvo">
             <tr class="data_list">
             <td align="center"  class="hidden-xs"><input type="checkbox" name="id" id="id" class="sall" value="{$subvo.id}" />{$subvo.id}</td>
                  <volist name="fields" id="ssvo">
    <td <if condition="$ssvo['fieldname'] neq 'title'">class="hidden-xs"</if> <eq name="key" value="0">style="text-indent:{$subvo['deep']*20}px"</eq>><eq name="ssvo['type']" value="0"><eq name="key" value="0"><gt name="subvo['deep']" value="0">|-</gt></eq>{$subvo[$ssvo['fieldname']]}</eq>
    <eq name="ssvo['type']" value="4"><img src="{:getThumbPath($subvo[$ssvo['fieldname']])}" width="50" height="50"></eq>
    <eq name="ssvo['type']" value="5"><input name="sort" width="30" type="hidden" value="{$subvo[$ssvo['fieldname']]}" size="4" /><a href="javascript:void(0);" onclick="update_sortClick('id','up',this,'sort','{:U('dosort',array('modules_id' => $modules_id,'tablename' => $tablename))}');">上</a><a href="javascript:void(0);" onclick="update_sortClick('id','',this,'sort','{:U('dosort',array('modules_id' => $modules_id,'tablename' => $tablename))}');">下</a></eq>
    </td>
    </volist>
   
    <td align="center"><a href="{:U('add',array('modules_id' => $modules_id, 'parent_id' => $svo['id'], 'fieldlist' => $fieldlist,'tablename' => $tablename))}">添加子级</a> | <a class="btn btn-success btn-xs" href="{:U('edit',array('parent_id' => $subvo['pid'],'modules_id' => $modules_id,'map'=>'id,'.$subvo['id'],'fieldlist' => $fieldlist,'tablename' => $tablename))}">编辑</a> | <a href="{:U('delete',array('modules_id' => $modules_id,'id'=>$subvo['id'],'tablename' => $tablename))}" onclick="return confirm('您确定要删除这条记录吗？');">删除</a></td>
    
     
             </tr>
        </volist>
  
</volist> 

   </table> 
    
    
    
    
    
     <div class="pages">
        
       
        <div class="fr">{$pages}</div>
      </div>
    
    
  

</body>
</html>
